
package org.apache.mina.common;

import java.net.SocketAddress;

/**
 * A connectionless transport can recycle existing sessions by assigning an
 * IoSessionRecyler to its {@link IoServiceConfig}.
 * 
 * 一个无连接的传输，能通过指定IoSessionRecyler到它的IoServiceConfig，再利用已经存在的会话。
 */
public interface IoSessionRecycler {
    /**
     * A dummy recycler that doesn't recycle any sessions. Using this recycler
     * will make all session lifecycle events to be fired for every I/O for all
     * connectionless sessions.
     * 
     * 一个空不回收任何会话的回收器。用该回收器将使得无连接的会话的每个IO的会话的生命周期事件都被触发。
     */
    static IoSessionRecycler NOOP = new IoSessionRecycler() {
                                      public void put(IoSession session) {
                                      }

                                      public IoSession recycle(
                                              SocketAddress localAddress,
                                              SocketAddress remoteAddress) {
                                          return null;
                                      }

                                      public void remove(IoSession session) {
                                      }
                                  };

    /**
     * Called when the underlying transport creates or writes a new
     * {@link IoSession}.
     * 
     * 当下层的传输创建或传送一个新的IoSession，时调用此方法。
     * 
     * @param session
     *            the new {@link IoSession}.
     */
    void put(IoSession session);

    /**
     * Attempts to retrieve a recycled {@link IoSession}.
     * 
     * 尝试检查一个被回收的IoSession。
     * 
     * @param localAddress
     *            the local socket address of the {@link IoSession} the
     *            transport wants to recycle.
     * @param remoteAddress
     *            the remote socket address of the {@link IoSession} the
     *            transport wants to recycle.
     * @return a recycled {@link IoSession}, or null if one cannot be found.
     */
    IoSession recycle(SocketAddress localAddress, SocketAddress remoteAddress);

    /**
     * Called when an {@link IoSession} is explicitly closed.
     * 
     * 当一个IoSession被明确关闭时，则会调用此方法。
     * 
     * @param session
     *            the new {@link IoSession}.
     */
    void remove(IoSession session);
}
